package com.base.cn.platform.os.controller.agent.income;

import com.base.cn.platform.os.common.constants.ConfigName;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.course.agent.user.AgentUserService;
import com.base.cn.platform.os.service.manage.config.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;
import java.util.TreeMap;

/**
 * 推广员收益接口Controller
 *
 * @author s.li
 * @create 2018-09-26-19:56
 */
@RestController
@RequestMapping("/api/agent/income")
public class ApiAgentIncomeController extends ApiBaseController {

    @Autowired
    private AgentUserService agentUserService;
    @Autowired
    SysConfigService sysConfigService;
    @Value("${api.path}")
    private String apiPath;

    /**
     * 查询用户总收益
     * @param userId 用户ID
     * @return Map<String,Object>
     */
    @RequestMapping("/queryAgentIncome")
    public Map<String,Object> queryAgentIncome(@RequestParam("userId")BigDecimal userId){
        Map<String, Object> agentUser = agentUserService.findAgentUserByUserId(userId, true, false, true);
        String path = apiPath +"/api/app/customerIndex";
        TreeMap<String,String> serviceMap = sysConfigService.getSysConfigContext(ConfigName.SERVICE);
        agentUser.put("customerUrl",serviceMap.get("context"));
        agentUser.put("consultationUrl",path);
        return ResultUtil.SUCCESS(agentUser);
    }

}
